/**
 * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ukao.steward.consts;


import android.widget.EditText;

import com.ukao.steward.R;
import com.ukao.steward.retrofit.SignTool;
import com.ukao.steward.util.CheckUtils;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.HashMap;

import static com.ukao.steward.util.CipherUtils.md5;

public class Constant   {


	/**
	 * 扫描跳转Activity RequestCode
	 */
	public static final int REQUEST_CODE = 111;
	public static final int BANEK_REQUEST_CODE = 1110;
	public static final int PAY_REQUEST_CODE =1520;
	public static final int ClOTHING_REQUEST_CODE = 11111;
	public static final int SEND_FACTORY_PAGE_SIZE =12;/*加载数量*/
	public static  final int    ALIAS_TAG = 2; //别名tag；
	public static final int  TRANS_NO  =1111;/* 填加运单号*/
	public static final int  TAG_NO  =1520;
	public static final String ARG_PARAM1 = "param1";
	public static final String ARG_PARAM2 = "param2";
	public static final String ARG_PARAM3 = "param3";
	public static final String ARG_PARAM4= "param4";
	public static final String ARG_PARAM5= "param5";
	public static final String ARG_PARAM6= "param6";
	public static final String ARG_PARAM7= "param7";
	public static final String ARG_PARAM8= "param8";
	public static final String ARG_PARAM9= "param9";
	public static final String ARG_PARAM10= "param10";
	public static final  String TIME_TYPE = "yyyy年 MM月 dd日";

	public static final int   PROJECT_ZERO= 0;
	public static final int   CLOTHING_ONE= 1;
	public static final int   SERVE_TWO= 2;
	public static final int   ADJUNCT_THREE= 3;
	public static final int   COLORS_FOUR= 4;
	public static final int   FLAW_FIVE= 5;
	public static final int   EFFECT_SIX= 6;
	public static final int   BRAND_SEVEN= 7;
	public static final int ADDITIONAL_SERVICES_EIGHT =8;



public static  final  String CODES="UD0L9AVPEMT8YW15TKZIAU7QJ8X7NT6F9HFSQ2T9Q98PS9C35QXJF2QNJDUN875K";

	/**
	 * 默认状态下的本地图片
	 */
	public static int[] mhomeSends = {
			R.drawable.home_order_receiving,
			R.drawable.home_take,
			R.drawable.home_send,
			R.drawable.home_clothing,
//			R.drawable.home_card,
			R.drawable.home_bing,
			0,
			0,
			0,
			0,
			R.drawable.home_store_crean_order,  //下单图片
			R.drawable.home_storage,            //入库图片
//			R.drawable.home_enter_factory, //送厂图片
			R.drawable.home_to_shop,       //到店图片
//			R.drawable.home_fetch_clothes,  //取衣图片
//			R.drawable.home_order_management, //订单管理
//			R.drawable.home_clothing_management,
//			R.drawable.home_member_management,
//			R.drawable.home_shop_inspection
	};

	public static int[] mhomeSend= {
			R.drawable.home_order_receiving,
			R.drawable.home_take,
			R.drawable.home_send,
			R.drawable.home_clothing,
			0,
			0,
			0,
			0,
			0,
			R.drawable.home_store_crean_order,  //下单图片
			R.drawable.home_storage,            //入库图片
			R.drawable.home_enter_factory, //送厂图片
			R.drawable.home_to_shop,       //到店图片
			R.drawable.home_fetch_clothes,  //取衣图片
			R.drawable.home_order_management, //订单管理
			R.drawable.home_clothing_management,
			R.drawable.home_member_management,
			R.drawable.home_shop_inspection

//			R.drawable.home_card,

//			R.drawable.hoem_generalize,

	};


	/**
	 * 默认状态下的本地图片
	 */
	public static int[] mhomeTakes = {
			R.drawable.home_enter_factory,
			R.drawable.home_leave_factory,
			R.drawable.home_enter_order,
			R.drawable.home_leave_order

	};



	/**
	 * 参数加密
	 */
	public  static HashMap<String,String> createParameter(HashMap<String,String> newparams ){
		String	appSecret=CODES;
		String code = SaveParams.getSerialcount();
		String  timestamp=System.currentTimeMillis()+"";
		newparams.put("account", code);
		newparams.put("appSecret", appSecret);
		newparams.put("timestamp",timestamp );
		String sign = SignTool.sign(newparams);
		newparams.remove("appSecret");
		newparams.put("sign", sign);
		return  newparams;

	}

	/**初始化ji加密参数
	 */
	public  static HashMap<String,String> firstParameter(HashMap<String,String> newparams  ){

		String CODE= SaveParams.getSerialcount();
		String  timestamp=System.currentTimeMillis()+"";
		newparams.put("account", CODE);
		newparams.put("timestamp",timestamp );
		String token = md5(md5(CODE) + timestamp);
		newparams.put("token",token );


		return  newparams;

	}

	public static  void calculate(String s, EditText mNameEt ){
		if (s.contains(".")) {
			if (s.length() - 1 - s.toString().indexOf(".") > 2) {
				s = (String) s.subSequence(0,
						s.indexOf(".") + 3);
				mNameEt.setText(s);
				mNameEt.setSelection(s.length());
			}
		}
		if (s.trim().substring(0).equals(".")) {
			s = "0" + s;
			mNameEt.setText(s);
			mNameEt.setSelection(2);
		}

		if (s.startsWith("0")
				&& s.toString().trim().length() > 1) {
			if (!s.toString().substring(1, 2).equals(".")) {
				mNameEt.setText(s.subSequence(0, 1));
				mNameEt.setSelection(1);
				return;
			}
		}
	}


	public static String getbusiness(String business) {
		if (CheckUtils.isEmpty(business))return  "";
		StringBuffer	mStringBuffer=new StringBuffer();
		try {
			JSONArray mJSONObject = new JSONArray(business);
			for (int i = 0; i <mJSONObject.length(); i++) {
				if (i==mJSONObject.length()-1){
					mStringBuffer.append( mJSONObject.getJSONObject(i).getString("name")) ;
				}else{
					mStringBuffer.append( mJSONObject.getJSONObject(i).getString("name")+"/") ;
				}

			}

		} catch (JSONException e) {
			e.printStackTrace();
			return "";
		}
		return mStringBuffer.toString();
	}

}



